/*
 * �쐬��: 2008/07/31
 *
 */
package tests;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import sort.result.SortResult;
import sort.ui.components.ResultTableModel;

/**
 * @author masaru-gotou
 *
 */
@SuppressWarnings("serial")
public class JTableTest extends JPanel {
	private JButton b_add;
	private ResultTableModel model; 
	/**
	 * 
	 *
	 */
	public JTableTest() {
        super(new GridLayout(1,0));
        
        List<SortResult> list = new ArrayList<SortResult>();
        SortResult result = new SortResult();
        result.setAlgorithmName("test");
        result.setElapsedTime(1000);
        list.add(result);
        
        this.model = new ResultTableModel(list);
		final JTable table = new JTable(this.model);
        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane);
        
        b_add = new JButton("add");
        b_add.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if ( e.getSource() == b_add ) {
			        SortResult result = new SortResult();
			        result.setAlgorithmName("added");
			        result.setElapsedTime(10001);
			        model.add(result);
				}
			}
        });
        add(b_add);
	}
	
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("SortResultViewerDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        JTableTest newContentPane = new JTableTest();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
